# -*- coding:utf-8 -*-
# @Time : 2021/12/24 上午9:59 
# @Author : zdy
# @File : UIModifySample.py
# desc:

from UI.ModifySample import Ui_ModifySample
from importQT import *
from Class.Devices import *

class UIModifySample(QDialog, Ui_ModifySample):
    def __init__(self, result: list,level:bool):
        super(UIModifySample, self).__init__()
        self.setupUi(self)
        self.setWindowFlags(Qt.WindowCloseButtonHint)
        self.setFixedSize(self.width(), self.height())
        self.applyResource()
        self.btnOK.clicked.connect(self.btnOK_clicked)
        self.btnCancel.clicked.connect(self.btnCancel_clicked)
        self.result = result
        if not level:
            self.chkflux.setVisible(False)
            self.txtflux.setVisible(False)
            self.chkweight.setVisible(False)
            self.txtweight.setVisible(False)

    def applyResource(self):
        self.setWindowIcon(getIcon())

    def btnOK_clicked(self):
        if self.chkName.checkState() == Qt.Unchecked and self.chkNO.checkState() == Qt.Unchecked \
                and self.chkweight.checkState() == Qt.Unchecked and self.chkflux.checkState() == Qt.Unchecked:
            self.reject()
        if self.chkName.checkState() == Qt.Checked:
            self.result.append(self.txtName.text())
        else:
            self.result.append(None)
        if self.chkNO.checkState() == Qt.Checked:
            self.result.append(self.txtNO.text())
        else:
            self.result.append(None)
        if self.chkweight.checkState() == Qt.Checked:
            self.result.append(self.txtweight.text())
        else:
            self.result.append(None)
        if self.chkflux.checkState() == Qt.Checked:
            self.result.append(self.txtflux.text())
        else:
            self.result.append(None)
        self.accept()

    def btnCancel_clicked(self):
        self.reject()
